package com.codeoss.module.stock.pagebean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.view.component.Message;
import com.codeoss.framework.view.pagebean.FormViewPageBean;
import com.codeoss.module.account.model.AccountInvoice;
import com.codeoss.module.account.service.IAccountInvoiceService;
import com.codeoss.module.purchase.model.PurchaseReturn;
import com.codeoss.module.purchase.service.IPurchaseReturnService;
import com.codeoss.module.stock.model.StockInConfirm;
import com.codeoss.module.stock.service.IStockInConfirmService;

@Service
public class StockInFormViewPageBean extends FormViewPageBean{
	@Autowired
	private IStockInConfirmService stockInConfirmService;
	@Autowired 
	private IPurchaseReturnService purchaseReturnService;
	@Autowired 
	private IAccountInvoiceService accountInvoiceService;
	@Transactional
	public void generateStockInConfirm() {
		// TODO Auto-generated method stub
		YunContext yunContext=YunContext.getCurrentContext();
		Long keyValue=(Long)getCurrentKeyValue();
		StockInConfirm stockInConfirm=stockInConfirmService.generateConfirm(keyValue);
		yunContext.addMessage(new Message("生成入库确认单 单据号"+stockInConfirm.getDocumentNo()));
	}
	
	@Transactional
	public void generatePurchaseReturn() {
		// TODO Auto-generated method stub
		YunContext yunContext=YunContext.getCurrentContext();
		Long keyValue=(Long)getCurrentKeyValue();
		PurchaseReturn purchaseReturn=purchaseReturnService.generatePurchaseReturn(keyValue);
		yunContext.addMessage(new Message("生成采购退货单 单据号"+purchaseReturn.getDocumentNo()));
	}
	
	@Transactional
	public void generateInvoice() {
		// TODO Auto-generated method stub
		YunContext yunContext=YunContext.getCurrentContext();
		Long keyValue=(Long)getCurrentKeyValue();
		AccountInvoice accountInvoice=accountInvoiceService.generateInvoiceFromStockIn(keyValue);
		yunContext.addMessage(new Message("生成发票 单据号"+accountInvoice.getDocumentNo()));
	}
}
